﻿using System;
using System.Net;
using System.Net.Mail;
using System.Text;
using System.Web.UI;
namespace HealthInsuranceMgm
{
    public partial class Contact_Us : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnReset_Click(object sender, EventArgs e)
        {
            txtAddress.Text = "";
            txtEmail.Text = "";
            txtFullName.Text = "";
            txtMessage.Text = "";
            txtPhone.Text = "";
        }

        private void ResetFrom()
        {
            txtAddress.Text = "";
            txtEmail.Text = "";
            txtFullName.Text = "";
            txtMessage.Text = "";
            txtPhone.Text = "";
        }
        private string MailBody()
        {
            string strHTML = "";
            strHTML += "Họ và tên: " + txtFullName.Text + "<br>";
            strHTML += "Địa chỉ: " + txtAddress.Text + "<br>";
            strHTML += "Điện thoại: " + txtPhone.Text + "<br>";
            strHTML += "Email: " + txtEmail.Text + "<br>";
            strHTML += "Đã gửi qua Form liên hệ với thông điệp:<br><b>";
            strHTML += txtMessage.Text + "</b>";
            return strHTML;
        }
        protected void btnSend_Click(object sender, EventArgs e)
        {
            var SmtpServer = new SmtpClient();
            SmtpServer.Credentials = new NetworkCredential("aptech.c1010l@gmail.com", "bkaptech");
            SmtpServer.Port = 587;
            SmtpServer.Host = "smtp.gmail.com";
            SmtpServer.EnableSsl = true;

            var mail = new MailMessage();

            try
            {
                mail.From = new MailAddress(txtEmail.Text, txtFullName.Text + " gửi từ form liên hệ", Encoding.UTF8);
                mail.To.Add("aptech.c1010l@gmail.com");
                mail.Subject = "Mail từ HealthInsuranceMgm Của Boss luuhuuchuan";
                mail.Body = MailBody();
                mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
                mail.ReplyTo = new MailAddress("aptech.c1010l@gmail.com");
                mail.Priority = MailPriority.High;
                mail.IsBodyHtml = true;
                SmtpServer.Send(mail);
                lblMessage.Text = "------------    Thank you have sent Message  to HealthInsuranceMgm !   ----------------";
                ResetFrom();
            }
            catch (Exception ex)
            {
                lblMessage.Text ="My Error: "+ ex.Message;
            }
        }
    }
}